package com.qk.management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.domain.activity.ActivityDO;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.mapper.ActivityMapper;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: chouh
 * @DateTime: 2025/10/13 0:39
 * @Description:
 */
@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public List<Activity> queryActivitiesByType(Integer type) {
        return activityMapper.queryActivitiesByType(type);
    }

    @Override
    public void updateActivity(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.updateById(activity);
    }

    @Override
    public Activity queryActivityById(Integer id) {
        return activityMapper.selectByIdd(id);
    }

    @Override
    public void addActivity(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.insertActivity(activity);
    }

    @Override
    public void deleteActivityById(Integer id) {
        activityMapper.deleteById(id);
    }

    @Override
    public PageResult<ActivityDO> getActivities(ActivityDTO activityDTO) {
        PageHelper.startPage(activityDTO.getPage(), activityDTO.getPageSize());
        List<ActivityDO> activities = activityMapper.selectBypage(activityDTO);
        Page<ActivityDO> pageInfo = (Page<ActivityDO>) activities;
        return PageResult.<ActivityDO>builder().total(Long.valueOf(pageInfo.getTotal()).intValue()).rows(pageInfo.getResult()).build();
    }
}
